package com.fxu.tpl.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fxu.framework.core.base.Cascade;
import com.fxu.framework.core.enums.EnumValid;
import com.fxu.framework.core.enums.StatusEnum;
import com.fxu.framework.core.sql.SEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Date;

import static com.baomidou.mybatisplus.annotation.FieldFill.UPDATE;

/***
 * <p>fxu</p>
 * 索引表：[index]的数据实体类
 * @author fangxu
 * @version 2019-09-23
 ***/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "Index", description = "索引")
@TableName("fxu_index")
public class Index extends SEntity<Index> implements Serializable {
/*=== 自动生成代码 开始 ===*/
    private static final long serialVersionUID = 6473615225495167818L;

    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "自增ID")
    private Long id;

    @ApiModelProperty(value = "表ID", required = true)
    //@NotNull(message = "表ID必须赋值")
    private Long tableId;

    @ApiModelProperty(value = "索引名", required = true)
    @NotBlank(message = "索引名必须赋值")
    @Size(max = 64, message = "索引名的长度必须小于64位")
    private String name;

    @ApiModelProperty(value = "字段类型", required = true)
    @NotNull(message = "字段类型必须赋值")
    private Integer type;

    @ApiModelProperty(value = "字段集合", required = true)
    @NotBlank(message = "字段集合必须赋值")
    @Size(max = 2048, message = "字段集合的长度必须小于2048位")
    private String columns;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    private Date updateTime;

    @ApiModelProperty(value = "状态[1:正常,0:删除]")
    @EnumValid(target = StatusEnum.class, message = "状态的值必须为{1:正常,0:删除}")
    private Integer status;

    @TableField(fill = UPDATE, update = "%s+1")
    @ApiModelProperty(value = "版本号")
    private Integer version;

    @TableField(exist = false)
    @ApiModelProperty(value = "表对象")
    @Cascade(thisField = "tableId", linkField = "id")
    private Table table;

    // 获得状态的说明
    public String getStatusText() {
        return StatusEnum.desc(status);
    }
/*=== 自动生成代码 结束 ===*/

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Index other = (Index) obj;
		if (columns == null) {
			if (other.columns != null)
				return false;
		} else if (!columns.equals(other.columns))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (status == null) {
			if (other.status != null)
				return false;
		} else if (!status.equals(other.status))
			return false;
		if (tableId == null) {
			if (other.tableId != null)
				return false;
		} else if (!tableId.equals(other.tableId))
			return false;
		return true;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((columns == null) ? 0 : columns.hashCode());
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime * result + ((status == null) ? 0 : status.hashCode());
		result = prime * result + ((tableId == null) ? 0 : tableId.hashCode());
		return result;
	}
}
